//
//  WHTabbar.swift
//  microblog
//
//  Created by Apple on 15/11/24.
//  Copyright © 2015年 Apple. All rights reserved.
//

import UIKit

class WHTabbar: UITabBar {

    override func layoutSubviews() {
        super.layoutSubviews()
        
        //计算item的宽度
        let width = bounds.size.width/5
        //创建frame
        let frame = CGRect(x: 0, y: 0, width: width, height: bounds.size.height)
        
        //记录是第几个view
        var index = 0
        //重新设计按钮的位置
        for view in self.subviews{
            if view is UIControl && !(view is UIButton){//防止后面位置出错。忽略撰写的frame值
                view.frame = CGRectOffset(frame, CGFloat(index) * width, 0)
                index += index == 1 ? 2 : 1
            }
        }
        
    }

}
